<template>
	<view class="content bgf8">
		<view class="boxes" v-for="i in list" @click="detail(i)">
			<view class="uniFlex2">
				<view class="text1">姓名：{{i.name}}</view>
				<view class="text">性别：<text v-if="i.sex==1">男</text><text v-else>女</text></view>
				<view class="text">年龄：{{i.age}}</view>
			</view>
			<view class="line">收货地址：{{i.province_name}}-{{i.city_name}}-{{i.area_name}}</view>
			<view class="line">详细地址：{{i.address}}</view>
			<view class="line">既往病史：{{i.jwbs}}</view>
			<view>过敏史：{{i.gms}}</view>
		</view>
		<view style="margin: 30upx;text-align: center;" v-if="list.length == 0">无数据，请添加</view>

		<drag-button :isDock="true" @btnClick="btnClick" />
	</view>
</template>

<script>
	import {
		list_users
	} from '@/request/api.js'
	import dragButton from "@/components/drag-button/drag-button.vue";
	export default {
		components: {
			dragButton
		},
		data() {
			return {
				list: []
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				this.list = [];
				list_users().then(res => {
					res.data.map(d => {
						Object.keys(d).forEach((k) => d[k] = d[k] || ' ');
						this.list.push(d)
					})
				})
			},
			detail(i) {
				let pages = getCurrentPages(); // 当前页面
				let beforePage = pages[pages.length - 2]; // 前一个页面
				// console.log(beforePage.route)
				if (beforePage.route == 'pages/guahao/guahao') {
					beforePage.$vm.jzeList = i //替换上个页面参数
					uni.navigateBack()
					console.log('选择就诊人后返回')
				} else {
					uni.navigateTo({
						url: './update?items=' + JSON.stringify(i)
					})
				}
			},
			btnClick() {
				console.log('添加')
				uni.navigateTo({
					url: './add'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #f8f8f8;
	}

	.boxes {
		padding: 30upx;
		background: #ffffff;
		margin-bottom: 20upx;
		font-size: 28upx;

		.text1 {
			width: 40%;
		}

		.text {
			width: 30%;
		}

		.line {
			margin: 16upx 0;
		}
	}
</style>